import {wasm_gauss_lower_pass_filter, wasm_lower_pass_filter} from 'zlyt-wasm';

export class ImageFilter {
    static gauss_lower_pass_filter(
        data: Uint8Array,
        extension: string,
        type: string,
        order: number,
        sigma: number): Promise<Blob> {
        const result = new Promise<Blob>((resolve, reject) => {
            try {
                const image = wasm_gauss_lower_pass_filter(data, extension, order, sigma);
                const resultImg = new Blob([image.buffer], {type});
                resolve(resultImg);
            } catch (e) {
                reject(`gauss filter error:${e}`);
            }
        });
        return result;
    }

    static lower_pass_filter(
        data: Uint8Array,
        extension: string,
        type: string, size: number): Promise<Blob> {
        const result =  new Promise<Blob>((resolve, reject) => {
            try {
                const image = wasm_lower_pass_filter(data, extension, size);
                const resultImg = new Blob([image.buffer], {type});
                resolve(resultImg);
            } catch (e) {
                reject(`lower pass filter error:${e}`);
            }
        });
        return result;
    }
}
